import React from 'react';
import cx from 'classnames';
import styles from './styles.m.less';

const COVER = 'cover';

export default class Image extends React.PureComponent {
    static defaultProps = {
        resizeMode: COVER,
        src: '',
    };

    render() {
        const {
            className, resizeMode, style, src, height, width, ...restProps
        } = this.props;
        return (
            <div
                className={cx(
                    styles.image,
                    {
                        [styles.cover]: resizeMode === COVER,
                    },
                    className
                )}
                style={{
                    backgroundImage: `url(${src})`,
                    width,
                    height,
                    ...style,
                }}
                {...restProps}
            />
        );
    }
}
